package diploma.kisel.modelas.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Domain class for device type (table - device_type).
 * 
 * @author Nikolay Kisel
 *
 */
@Entity
@Table(name = "device_type")
@NamedQueries({
		@NamedQuery(name = "DeviceType.findAll", query = "select d from DeviceType d"),
		@NamedQuery(name = "DeviceType.findById", query = "select d from DeviceType d where d.id=:id") })
public class DeviceType {

	private String id;
	private String description;

	// for one to many mapping
	private Set<Device> devices = new HashSet<Device>();

	public DeviceType() {

	}

	public DeviceType(String id, String description) {
		this.id = id;
		this.description = description;
	}

	@Id
	@Column(name = "id_device_type")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@OneToMany(mappedBy = "deviceType", cascade = CascadeType.ALL, orphanRemoval = true)
	public Set<Device> getDevices() {
		return devices;
	}

	public void setDevices(Set<Device> devices) {
		this.devices = devices;
	}

	@Override
	public String toString() {
		return id;
	}

}
